﻿using System;
using System.Collections.Generic;
using System.Text;
using ZhangBY.Common;

namespace ZhangBY.Config
{
   public class CompanyBaseConfig
    {
       private static CompanyBaseConfigInfo m_comBaseConfigInfo;
       private static CompanyBaseConfigFileManager config ;
       private string fullFileName;
       public CompanyBaseConfig(string userFolder)
       {
           if (Utils.StrIsNullOrEmpty(userFolder)) return;
           fullFileName = Utils.GetMapPath(string.Format("~/aspx/company/userfolder/{0}/{1}", userFolder, "usersystem.config"));
           if (!Utils.FileExists(fullFileName))
           {
               Utils.FolderExistence(Utils.GetMapPath(string.Format("~/aspx/company/userfolder/{0}", userFolder)),true);
               Serialiaze(new CompanyBaseConfigInfo(), fullFileName);
           }
           config = new CompanyBaseConfigFileManager("usersystem.config", userFolder);
           m_comBaseConfigInfo = config.LoadConfig();
       }
       /// <summary>
       /// 重设配置类实例
       /// </summary>
       public  void ResetConfig()
       {
           m_comBaseConfigInfo = config.LoadRealConfig();
       }
       /// <summary>
       /// 获取配置实例
       /// </summary>
       /// <returns></returns>
       public  CompanyBaseConfigInfo GetConfig()
       {
           return m_comBaseConfigInfo;
       }
       #region 配置类序列化反序列化

       /// <summary>
       /// 序列化配置信息为XML
       /// </summary>
       /// <param name="configinfo">配置信息</param>
       /// <param name="configFilePath">配置文件完整路径</param>
       public  CompanyBaseConfigInfo Serialiaze(CompanyBaseConfigInfo configinfo, string configFilePath)
       {
           bool f = SerializationHelper.Save(configinfo, configFilePath);
           return configinfo;
       }


       /// <summary>
       /// 反序列化到对象
       /// </summary>
       /// <param name="configFilePath">配置文件路径</param>
       /// <returns></returns>
       public  CompanyBaseConfigInfo Deserialize(string configFilePath)
       {
           return (CompanyBaseConfigInfo)SerializationHelper.Load(typeof(CompanyBaseConfigInfo), configFilePath);
       }

       #endregion
    }
}
